#pragma once
#include "CFrameworkElement.h"


class CBrush;

class CControl :
	public CFrameworkElement
{

public: 
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XUINT32 GetTypeIndex() const;
	virtual XINT32 CanHaveChildren();
	virtual XBOOL GetIsLayoutElement();
	virtual HRESULT SetValue(CDependencyProperty * pdp, CValue * pValue);
	virtual HRESULT PullInheritedTextFormatting();
	HRESULT GetImplementationRoot(CUIElement * * ppResult);
	virtual HRESULT CreationComplete();
	virtual HRESULT CoerceIsEnabled(XBOOL fIsEnabled, XBOOL fCoerceChildren);
	virtual XBOOL Focus(enum FocusState focusState);
	HRESULT Focus(enum FocusState focusState, XBOOL * returnValue);
	void SuppressIsEnabled(XBOOL fSuppress);
	HRESULT GetTemplateChild(XUINT32 cChildName, XUINT16 * pChildName, CDependencyObject * * ppChild);
	virtual HRESULT GetTemplate(CControlTemplate * * ppTemplate);
	virtual XBOOL IsFocusable();
	virtual HRESULT GetValueFromBuiltInStyle(XUINT32 uPropertyId, XBOOL bIsCoreProperty, CValue * pValue, XBOOL * pbGotValue);
	XBOOL IsTabStop();
	XINT32 TabIndex();
	enum KeyboardNavigationMode TabNavigation();
	virtual XBOOL IsFocused();
	virtual HRESULT UpdateFocusState(enum FocusState focusState);
	virtual HRESULT SubscribeToPropertyChanges(struct XamlPropertyToken tokSourceProperty, CDependencyObject * pdoTarget, struct XamlPropertyToken tokTargetProperty);
	virtual HRESULT RemoveTemplateBinding(CDependencyObject * pdoTarget, CDependencyProperty * pdpTarget);
	virtual XBOOL IsUpdatingBindings();
	HRESULT RefreshTemplateBindings();
	bool SupportsBuiltInStyles();
	virtual XBOOL CanCreateInPeerUpdate();
	virtual HRESULT ShouldBringIntoViewOnKeyboardFocus(XBOOL * pShouldShouldBringIntoView);
	static HRESULT Enabled(struct Xcp_IDependencyObject * pObject, XUINT32 cArgs, CValue * ppArgs, CValue * pResult);
protected: 
	virtual HRESULT EnterImpl(CDependencyObject * pNamescopeOwner, struct EnterParams params);
	virtual HRESULT LeaveImpl(CDependencyObject * pNamescopeOwner, struct LeaveParams params);
	virtual HRESULT MeasureOverride(struct XSIZEF availableSize, struct XSIZEF & desiredSize);
	virtual HRESULT ArrangeOverride(struct XSIZEF finalSize, struct XSIZEF & newFinalSize);
	virtual void SetIsUpdatingBindings(XBOOL fIsUpdatingBinding);
	virtual HRESULT SubscribeToCoreProperty(CDependencyProperty * pdpSource, CDependencyObject * pdoTarget, struct XamlPropertyToken tokTargetProperty);
	virtual HRESULT NotifyPropertyChanged(CDependencyProperty * pdp, CValue * pValue);
	virtual HRESULT RefreshSubscriptions(struct PropertySubscriptions * pSubscriptions, CValue * pValue);
	virtual struct TargetPropertySubscription * LookupSubscription(struct PropertySubscriptions * pSubscriptions, CDependencyObject * pdoTarget, CDependencyProperty * pdpTarget);
	virtual struct PropertySubscriptions * LookupPropertySubscriptions(CDependencyProperty * pdpSource);
	virtual HRESULT EnsurePropertySubscriptions(CDependencyProperty * pdpSource, struct PropertySubscriptions * * ppSubscriptions);
	virtual HRESULT RaiseIsEnabledChangedEvent(CValue * pValue);

private: 
	CControl(CCoreServices * pCore);
protected: 
	CControl();
	virtual ~CControl();
private: 
	void Initialize(CCoreServices * pCore);
	HRESULT ApplyBuiltInStyle();
	HRESULT GetBuiltInStyle(CStyle * * ppStyle);
	virtual HRESULT GetNativeBuiltInStyle(CStyle * * ppStyle);
	HRESULT PropagateInheritedProperty(CUIElement * pUIElement, CDependencyProperty * pdp);
	void ClearPropertySubscriptions();
	XBOOL PropertyTypesCompatible(CDependencyProperty * pdpSource, CDependencyProperty * pdpTarget, XBOOL * pfRequiresTypeCheck);
public: 
	XBOOL m_fIsTabStop;
	XINT32 m_cTabIndex;
	enum KeyboardNavigationMode m_eKeyboardNavigationMode;
	struct XRECTF_RB m_padding;
	struct XRECTF_RB m_borderThickness;
	enum HorizontalAlignment m_horizontalContentAlignment;
	enum VerticalAlignment m_verticalContentAlignment;
	CControlTemplate * m_pTemplate;
	CBrush * m_pBackground;
	CBrush * m_pBorderBrush;
	CDependencyObject * m_pDefaultStyleKey;
	enum FocusState m_eFocusState;
protected: 
	CXcpList<PropertySubscriptions> * m_pPropertySubscriptions;
	XBOOL m_fIsUpdatingBindings;
	XUINT32 m_nCustomType;
private: 
	CStyle * m_pBuiltInStyle;
	struct
	{
		XBOOL m_fIsBuiltInStyleApplied:1;
		XBOOL m_fSuppressIsEnabled:1;
	};


};